package it.controllocredito.frontend.activities;

import java.util.ArrayList;

import it.controllocredito.R;
import it.controllocredito.backend.persistence.bean.RegistroChiamate;
import it.controllocredito.backend.phone.calllog.ManagerCallLogHandler;
import it.controllocredito.frontend.util.RegistroChiamateArrayAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;

public class RegistroChiamateActivity extends SherlockFragmentActivity {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.registro_chiamate_activity);

		 Button button1 = (Button)findViewById(R.id.btn_registro_back);
	        button1.setOnClickListener(new OnClickListener() {
				public void onClick(View v) {
					Intent intent = new Intent(
							getApplicationContext(),
							MainFragmentActivity.class
						);
					startActivity(intent);
				}
			});	
		
		ManagerCallLogHandler managerCallLogHandler = new ManagerCallLogHandler(
				getApplicationContext());

		ArrayList<RegistroChiamate> listaRegistroChiamate = managerCallLogHandler
				.aggiornaRegistroChiamate(null);

		RegistroChiamate[] x = new RegistroChiamate[listaRegistroChiamate
				.size()];

		int i = 0;

		for (RegistroChiamate registroChiamata : listaRegistroChiamate) {
			x[i] = registroChiamata;
			i++;
		}

		RegistroChiamateArrayAdapter registroChiamateArrayAdapter = new RegistroChiamateArrayAdapter(
				getApplicationContext(), x);

		final ListView listView = (ListView) findViewById(R.id.mylist);

		// Assign adapter to ListView
		listView.setAdapter(registroChiamateArrayAdapter);

		// FINE LISTVIEW
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getSupportMenuInflater();
		inflater.inflate(R.menu.main_menu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		return true;
	}

}